package lpc

import (
	"errors"
	"os"
	"runtime"
	"sync"
)

var (
	APIDB           = map[string]*APIInfo{}
	GOOS            = runtime.GOOS
	PWD, _          = os.Getwd()
	SOCK_FILE_PATH  = GetAPISockFile()
	locker          = sync.RWMutex{}
	ErrAPINotFound  = errors.New("api not found in api db")
	ErrDictNotFound = errors.New("key not found in data")
	PID             = -1
)

type APIInfo struct {
	Name        string          `json:"Name"`
	BinFilePath string          `json:"BinFilePath"`
	Flags       map[string]Flag `json:"Flags"`
	Executale   string          `json:"executable"`
}

type Flag struct {
	Name     string
	Value    interface{}
	DefValue string
	Usage    string
}

func APIDBUpdate(apiinfo *APIInfo) {
	locker.Lock()
	APIDB[apiinfo.Name] = apiinfo
	locker.Unlock()

}
